package operation;
import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowedBook implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书....");
        System.out.println("请输入你要借阅的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        //1.先遍历数组 查找是否存在要借阅的图书
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                //2.如果存在 检查 是否已经被借出
                if(book.isBorrowed()) {
                    System.out.println("这本书已经被借出了！");
                }else {
                    //3. 如果没有借出 可以借
                    book.setBorrowed(true);
                    System.out.println(book);
                    System.out.println("借阅成功！！");
                }
                return;
            }
        }
        //4.如果不存在 则不能借阅
        System.out.println("没有你要找的这本书，无法借阅！！");
    }
}
